import SearchPage from "../components/searchpage/SearchPage.vue";
import OperationPage from "../components/operationpage/OperationPage.vue";
import HistoryRecordPage from "../components/historyrecord/HistoryRecordPage.vue";
import HomePage from "../components/homepage/HomePage.vue";
import {useSearchPageStore} from "../store/SearchPageStore.js";
import {useOperationPageStore} from "../store/OperationPageStore.js";
import {useHomePageStore} from "../store/HomePageStore.js";
import {useHistoryRecordStore} from "../store/HistoryRecordStore.js";

export const useRoutes = [
    {
        path: '/',
        component: HomePage,
        async beforeEnter(to, from) {
             const homePageStore = useHomePageStore();
             homePageStore.initHomePage()
        },
        children: [
            {
                path: '/search',
                component: SearchPage,
                async beforeEnter(to, from) {
                    const store = useSearchPageStore();
                    store.$reset()
                    await store.initSearchPage();
                }
            },
            {
                path: '/operation',
                component: OperationPage,
                async beforeEnter(to, from) {
                    const store = useOperationPageStore();
                    store.$reset()
                    await store.operateMenus();
                }
            },
            {
                path: '/historyRecord',
                component: HistoryRecordPage,
                beforeEnter:(to, from) => {
                    const store = useHistoryRecordStore();
                    store.initPage()
                }
            }
        ]
    }
]